//
//  TLBrowseViewController.m
//  FunnyVideo
//
//  Created by 李鑫 on 15/10/20.
//  Copyright © 2015年 NewEggTech. All rights reserved.
//

#import "TLBrowseViewController.h"
#import "TLBrowseCreateManger.h"
#import "ZLSwipeableView.h"
#import "UIColor+FlatColors.h"
#import "TLSwipeView.h"
#import "TLGifAniButton.h"


@interface TLBrowseViewController ()<ZLSwipeableViewDataSource,
ZLSwipeableViewDelegate, UIActionSheetDelegate>

@property (nonatomic, weak) IBOutlet ZLSwipeableView *swipeableView;

@property (nonatomic, strong) NSMutableArray *swipViews;
@end

@implementation TLBrowseViewController

#pragma mark -- View LifeCycle

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.swipViews = [[NSMutableArray alloc] initWithCapacity:1];
    // Do any additional setup after loading the view.
}

- (void)viewDidAppear:(BOOL)animated{
    self.swipeableView.delegate = self;
    self.swipeableView.dataSource = self;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark -- Browse Dislike & Like Action
- (IBAction)dislikeActionTapped:(id)sender {
    [self.swipeableView swipeTopViewToLeft];
}

- (IBAction)likeActionTapped:(id)sender {
    [self.swipeableView swipeTopViewToRight];
}

- (IBAction)commentBrowseVideo:(id)sender {
    
}


#pragma mark -- ZLSwipeableViewDataSource

- (TLSwipeView *)nextViewForSwipeableView:(ZLSwipeableView *)swipeableView{
    TLSwipeView *swpView = [[[NSBundle mainBundle] loadNibNamed:@"VideoThumbCard" owner:self options:nil] objectAtIndex:0];
    
    [self.swipViews removeAllObjects];
    [self.swipViews addObject:swpView];
    
    return swpView;
}

#pragma mark -- ZLSwipeableViewDelegate
- (void)swipeableView:(ZLSwipeableView *)swipeableView
         didSwipeView:(UIView *)view
          inDirection:(ZLSwipeableViewDirection)direction {
    
    NSLog(@"did swipe in direction: %zd %@", direction,NSStringFromCGRect(view.frame));
    
    if(swipeableView.direction == ZLSwipeableViewDirectionLeft)
    {
        //[((TLGifAniButton *)[(TLSwipeView *)view supportAniBtn]) select];
        TLSwipeView *swpView = (TLSwipeView *)view;
        
        TLGifAniButton *gifBtn = [swpView supportAniBtn];
        
        [gifBtn unselect];
        [swpView unsupport];
    }
    else if(swipeableView.direction == ZLSwipeableViewDirectionRight)
    {
        //[((TLGifAniButton *)[(TLSwipeView *)view supportAniBtn]) select];
        TLSwipeView *swpView = (TLSwipeView *)view;
        
        TLGifAniButton *gifBtn = [swpView supportAniBtn];
        
        [gifBtn select];
        [swpView support];
    }
}

- (void)swipeableView:(ZLSwipeableView *)swipeableView
       didCancelSwipe:(UIView *)view {
    NSLog(@"did cancel swipe");
}

- (void)swipeableView:(ZLSwipeableView *)swipeableView
  didStartSwipingView:(UIView *)view
           atLocation:(CGPoint)location {
    NSLog(@"did start swiping at location: x %f, y %f %@", location.x, location.y,NSStringFromCGRect(view.frame));
}

- (void)swipeableView:(ZLSwipeableView *)swipeableView
          swipingView:(UIView *)view
           atLocation:(CGPoint)location
          translation:(CGPoint)translation {
    NSLog(@"swiping at location: x %f, y %f, translation: x %f, y %f  %@",
          location.x, location.y, translation.x, translation.y,NSStringFromCGRect(view.frame));
}

- (void)swipeableView:(ZLSwipeableView *)swipeableView
    didEndSwipingView:(UIView *)view
           atLocation:(CGPoint)location {
    TLSwipeView *playerView = (TLSwipeView *)view;
    
    [playerView stopPlayer];
    
    [self.swipViews removeAllObjects];
    NSLog(@"did end swiping at location: x %f, y %f  %@", location.x, location.y,NSStringFromCGRect(view.frame));
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
